<template>
  <div class="square-block home-section">
    <div class="home-title">模型广场</div>
    <div class="square-content">
      <div
        v-for="(item, index) in modelList"
        class="item"
        :class="{ 'is-active': index === activeIndex }"
        :style="itemStyle(index)"
        :key="item.id"
        @click="changeActive(index)"
      >
        <div class="cover"></div>
        <div class="inner">
          <div class="inner-title">{{ item.elementTitle || "title" }}</div>
          <div class="inner-sub-title" v-show="isActive(index)">
            {{ item.elementFrame }}
          </div>
          <div class="inner-content">
            <div v-html="item.remark"></div>
          </div>
          <div class="inner-tags" v-show="isActive(index)">
            <span
              v-for="(tag, _index) in item.elementTagList?.slice(0, 4) || []"
              :key="_index"
              class="tag"
              >{{ tag }}</span
            >
          </div>
          <img
            src="@/assets/more-arrow.svg"
            v-show="!isActive(index)"
            alt=""
            class="more-icon"
          />
          <router-link
            :to="`/model/square/detail?id=${item.id}`"
            target="_blank"
          >
            <div class="active-more" v-show="isActive(index)">
              <span>查看</span>
              <img src="@/assets/more-arrow-white.svg" alt="" />
            </div>
          </router-link>
        </div>
      </div>
    </div>
    <More path="/model/square" />
  </div>
</template>

<script setup>
import More from "./more.vue";

const modelList = ref([]);
const activeIndex = ref(0);
const changeActive = (index) => {
  activeIndex.value = index;
};

const itemStyle = computed(() => {
  return (index) => {
    return {
      backgroundImage: `url('/square-item-${index + 1}.png')`,
    };
  };
});
const isActive = computed(() => {
  return (index) => {
    return index === activeIndex.value;
  };
});

const $api = inject("$api");
const getData = async () => {
  const { data } = await $api.provide.getCustomerList({
    pageNum: 1,
    pageSize: 4,
    elementShareType: 1,
    elementType: 2,
    status: 1,
  });
  modelList.value = data;
};

onMounted(() => {
  getData();
});
</script>

<style lang="less" scoped>
.square-block {
  padding: 80px 0 72px;
  background: #fff;
  .square-content {
    width: 1329px;
    margin: 48px 0 40px;
    display: flex;
  }
}
.item {
  position: relative;
  box-sizing: border-box;
  height: 400px;
  width: 224px;
  margin-left: 12px;
  transition: all 0.4s;
  overflow: hidden;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  .cover,
  .inner {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
  }
  .cover {
    opacity: 0;
    background: linear-gradient(
      180deg,
      rgba(7, 73, 242, 0.8) 0%,
      rgba(7, 73, 242, 0.8) 100%
    );
    transition: opacity 0.4s ease-in-out;
  }
  .inner {
    box-sizing: border-box;
    padding: 56px 34px 37px 29px;
    &-title,
    &-sub-title {
      font-weight: 500;
      font-size: 24px;
      color: @text-default;
      margin-bottom: 13px;
    }
    &-content {
      font-size: 14px;
      line-height: 20px;
      color: @text-light;
      .multiline-overflow(8);
    }
    .more-icon {
      position: absolute;
      width: 24px;
      height: 24px;
      bottom: 37px;
    }
    .active-more {
      position: absolute;
      right: 34px;
      bottom: 31px;
      background: #ff0d73;
      width: 90px;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      span {
        font-size: 18px;
        color: #fff;
        margin-right: 3px;
      }
      img {
        width: 18px;
        height: 18px;
      }
    }
  }
  .tag {
    color: #fff;
    font-size: 14px;
    line-height: 20px;
    padding: 3px 19px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.3);
    margin-right: 13px;
  }
  &:first-child {
    margin-left: 0;
  }
  &.is-active {
    width: 621px;
    .cover {
      opacity: 1;
    }
    .inner {
      padding-bottom: 31px;
      padding-left: 44px;
      padding-right: 160px;
      > div {
        color: #fff;
      }
      &-title {
        margin-bottom: 22px;
      }
      &-sub-title {
        margin-bottom: 16px;
      }
      &-content {
        margin-bottom: 40px;
        .multiline-overflow(3);
      }
    }
  }
}
</style>
